package com.estronger.shopmanage.view;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.os.Handler;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.TimePicker;

import com.estronger.shopmanage.R;
import com.estronger.shopmanage.adapter.ArrayWheelAdapter;
import com.estronger.shopmanage.listener.OnWheelChangedListener;
import com.estronger.shopmanage.utils.DateUtils;
import com.estronger.shopmanage.utils.TimeUtils;
import com.estronger.shopmanage.utils.Toast;

import java.util.Calendar;

public class AppDialog {


    //双按钮弹出选择框
    public static Dialog createDialog(final Activity activity, String cts, final String content, OnClickListener listener, String id) {

        View view = LayoutInflater.from(activity).inflate(
                R.layout.call_dialog2, null);
        final Dialog dialog = new Dialog(activity, R.style.dialog);
        dialog.setContentView(view);
        // 标题
        // TextView tView = (TextView) view.findViewById(R.id.tvdialogtitle);
        // tView.setText(title);
        if (!TextUtils.isEmpty(cts)) {
            TextView tView = (TextView) view.findViewById(R.id.call_who);
            tView.setText(cts);
        }
        // 弹窗口的内容
        TextView message = (TextView) view.findViewById(R.id.message_content);
        message.setVisibility(View.VISIBLE);
        message.setText(content);
        Button okButton = (Button) view.findViewById(R.id.ok);
        Button cancelButton = (Button) view.findViewById(R.id.cancel);
        cancelButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                dialog.dismiss();
            }
        });
        if (listener != null) {
            okButton.setOnClickListener(listener);
            okButton.setTag(id);
        }
        return dialog;
    }

    public static Dialog createPgDialog(final Activity activity, String cts,
                                        final String content, OnClickListener listener, int position) {

        View view = LayoutInflater.from(activity).inflate(
                R.layout.call_dialog3, null);
        final Dialog dialog = new Dialog(activity, R.style.dialog);
        dialog.setContentView(view);
        // 标题
        // TextView tView = (TextView) view.findViewById(R.id.tvdialogtitle);
        // tView.setText(title);
        if (!TextUtils.isEmpty(cts)) {
            TextView tView = (TextView) view.findViewById(R.id.tvfCall_who);
            tView.setText(cts);
        }
        // 弹窗口的内容
        TextView message = (TextView) view.findViewById(R.id.tvfMessage_content);
        message.setVisibility(View.VISIBLE);
        message.setText(content);
        Button okButton = (Button) view.findViewById(R.id.btnfSure);
        Button cancelButton = (Button) view.findViewById(R.id.btnfCancel);
        if (listener != null) {
            okButton.setOnClickListener(listener);
            okButton.setTag(position);
            cancelButton.setOnClickListener(listener);
            cancelButton.setTag(position);
        }
        return dialog;
    }

    public static Dialog createPgDialog(final Activity activity, String cts,
                                        final String content, OnClickListener listener, String id) {

        View view = LayoutInflater.from(activity).inflate(
                R.layout.call_dialog3, null);
        final Dialog dialog = new Dialog(activity, R.style.dialog);
        dialog.setContentView(view);
        // 标题
        // TextView tView = (TextView) view.findViewById(R.id.tvdialogtitle);
        // tView.setText(title);
        if (!TextUtils.isEmpty(cts)) {
            TextView tView = (TextView) view.findViewById(R.id.tvfCall_who);
            tView.setText(cts);
        }
        // 弹窗口的内容
        TextView message = (TextView) view.findViewById(R.id.tvfMessage_content);
        message.setVisibility(View.VISIBLE);
        message.setText(content);
        Button okButton = (Button) view.findViewById(R.id.btnfSure);
        Button cancelButton = (Button) view.findViewById(R.id.btnfCancel);
        if (listener != null) {
            okButton.setOnClickListener(listener);
            okButton.setTag(id);
            cancelButton.setOnClickListener(listener);
            cancelButton.setTag(id);
        }
        return dialog;
    }

    public static Dialog createPicker(Activity activity, final TextView date) {

        View view = LayoutInflater.from(activity).inflate(
                R.layout.picker_dialog, null);
        final Dialog dialog = new Dialog(activity, R.style.dialog);
        dialog.setContentView(view);
        initView(view);
        setOriTime();
        Button cancelButton = (Button) view.findViewById(R.id.cancel);
        cancelButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                dialog.dismiss();
            }
        });
        Button okButton = (Button) view.findViewById(R.id.ok);
        okButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                date.setText(showDate());
                dialog.dismiss();
            }
        });

        return dialog;
    }

    public static Dialog createPickerTJstart(final Context context, final TextView tv, final String datenow,String minTime,String maxTime){
        SFDialog dialog = (SFDialog) createPickerTJstart(context,tv,datenow);
        dialog.setMaxDay(maxTime);
        dialog.setMinDay(minTime);
        return dialog;
    }

    public static Dialog createPickerTJstart(final Context context, final TextView tv, final String datenow) {

        View view = LayoutInflater.from(context).inflate(
                R.layout.picker_dialog, null);
        final SFDialog dialog = new SFDialog(context, R.style.dialog);
        dialog.setContentView(view);
        initView2(view);
        setOriTime2(datenow);
        Button cancelButton = (Button) view.findViewById(R.id.cancel);
        cancelButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                dialog.dismiss();
            }
        });
        Button okButton = (Button) view.findViewById(R.id.ok);
        okButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                String today = TimeUtils.getSystime("yyyy-MM-dd");
                String select = showDate2();

                if (!TextUtils.isEmpty(dialog.getMinDay())){
                    long diff = TimeUtils.diffSubtractTime(dialog.getMinDay(), select, "yyyy-MM-dd");
                    if (diff > 0){
                        Toast.show(context, "时间不能小于" + dialog.getMinDay(), 2000);
                        return;
                    }
                }
                if (!TextUtils.isEmpty(dialog.getMaxDay())){
                    long diff = TimeUtils.diffSubtractTime(dialog.getMaxDay(), select, "yyyy-MM-dd");
                    if (diff < 0){
                        Toast.show(context, "时间不能大于" + dialog.getMaxDay(), 2000);
                        return;
                    }
                }

                TimeUtils.diffSubtractTime(today, select, "yyyy-MM-dd");
                if (TimeUtils.diffSubtractTime(today, select, "yyyy-MM-dd") <= 63158400000L) {
                    tv.setText(showDate2());
                    dialog.dismiss();
                } else {
                    Toast.show(context, "开始日期不能大于过去的两年", 2000);
                    setOriTime3();
                }
            }
        });

        return dialog;
    }

    public static Dialog createPickerTJend(final Context context, final TextView tv, final String datenow) {

        View view = LayoutInflater.from(context).inflate(
                R.layout.picker_dialog, null);
        final Dialog dialog = new Dialog(context, R.style.dialog);
        dialog.setContentView(view);
        initView2(view);
        setOriTime2(datenow);
        Button cancelButton = (Button) view.findViewById(R.id.cancel);
        cancelButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                dialog.dismiss();
            }
        });
        Button okButton = (Button) view.findViewById(R.id.ok);
        okButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                String today = TimeUtils.getSystime("yyyy-MM-dd");
                String select = showDate2();
                if (TimeUtils.diffTime(select, today, "yyyy-MM-dd")) {
                    tv.setText(showDate2());
                    dialog.dismiss();
                } else {
                    Toast.show(context, "结束日期不能大于今天", 2000);
                    setOriTime2("");
                }
            }
        });

        return dialog;
    }

    // private LinearLayout layout = null ;
    private static WheelView yearWV = null;
    private static WheelView monthWV = null;
    private static WheelView dayWV = null;
    private static WheelView hourWV = null;
    private static WheelView minuteWV = null;

    // 滚轮上的数据，字符串数组
    static String[] yearArrayString = null;
    static String[] dayArrayString = null;
    static String[] monthArrayString = null;
    static String[] hourArrayString = null;
    static String[] minuteArrayString = null;
    static Calendar c = null;
    static int year;
    static int month;


    public static void initView(View view) {
        // 获取当前系统时间
        c = Calendar.getInstance();
        yearWV = (WheelView) view.findViewById(R.id.time_year);
        monthWV = (WheelView) view.findViewById(R.id.time_month);
        dayWV = (WheelView) view.findViewById(R.id.time_day);
        hourWV = (WheelView) view.findViewById(R.id.time_hour);
        minuteWV = (WheelView) view.findViewById(R.id.time_minute);
        yearArrayString = getYEARArray(2015, 19);
        monthArrayString = getDayArray(12);
        hourArrayString = getHMArray(24);
        minuteArrayString = getHMArray(60);
        // 设置每个滚轮的行数
        yearWV.setVisibleItems(5);
        monthWV.setVisibleItems(5);
        dayWV.setVisibleItems(5);
        hourWV.setVisibleItems(5);
        minuteWV.setVisibleItems(5);

        // 设置滚轮的标签
        yearWV.setLabel("年");
        monthWV.setLabel("月");
        dayWV.setLabel("日");
        hourWV.setLabel("时");
        minuteWV.setLabel("分");
        yearWV.setCyclic(true);
        monthWV.setCyclic(true);
        dayWV.setCyclic(true);
        hourWV.setCyclic(true);
        minuteWV.setCyclic(true);


        setData();
    }

    public static void initView2(View view) {
        // 获取当前系统时间
        c = Calendar.getInstance();
        yearWV = (WheelView) view.findViewById(R.id.time_year);
        monthWV = (WheelView) view.findViewById(R.id.time_month);
        dayWV = (WheelView) view.findViewById(R.id.time_day);
        hourWV = (WheelView) view.findViewById(R.id.time_hour);
        minuteWV = (WheelView) view.findViewById(R.id.time_minute);
        hourWV.setVisibility(View.GONE);
        minuteWV.setVisibility(View.GONE);
        yearArrayString = getYEARArray(2015, 19);
        monthArrayString = getDayArray(12);
        //hourArrayString = getHMArray(24);
        //minuteArrayString = getHMArray(60);
        // 设置每个滚轮的行数
        yearWV.setVisibleItems(5);
        monthWV.setVisibleItems(5);
        dayWV.setVisibleItems(5);
        //hourWV.setVisibleItems(5);
        //minuteWV.setVisibleItems(5);

        // 设置滚轮的标签
        yearWV.setLabel("年");
        monthWV.setLabel("月");
        dayWV.setLabel("日");
        hourWV.setLabel("时");
        minuteWV.setLabel("分");
        yearWV.setCyclic(true);
        monthWV.setCyclic(true);
        dayWV.setCyclic(true);
        //hourWV.setCyclic(true);
        //minuteWV.setCyclic(true);


        setData2();
    }

    /**
     * 给滚轮提供数据
     */
    private static void setData() {
        // 给滚轮提供数据
        yearWV.setAdapter(new ArrayWheelAdapter<String>(yearArrayString));
        monthWV.setAdapter(new ArrayWheelAdapter<String>(monthArrayString));
        hourWV.setAdapter(new ArrayWheelAdapter<String>(hourArrayString));
        minuteWV.setAdapter(new ArrayWheelAdapter<String>(minuteArrayString));

        yearWV.addChangingListener(new OnWheelChangedListener() {
            @Override
            public void onChanged(WheelView wheel, int oldValue, int newValue) {
                // TODO Auto-generated method stub
                // 获取年和月
                year = Integer.parseInt(yearArrayString[yearWV.getCurrentItem()]);
                month = Integer.parseInt(monthArrayString[monthWV
                        .getCurrentItem()]);
                // 根据年和月生成天数数组
                dayArrayString = getDayArray(getDay(year, month));
                // 给天数的滚轮设置数据
                dayWV.setAdapter(new ArrayWheelAdapter<String>(dayArrayString));
                // 防止数组越界
                if (dayWV.getCurrentItem() >= dayArrayString.length) {
                    dayWV.setCurrentItem(dayArrayString.length - 1);
                }
                // 显示的时间
                showDate();
            }
        });

        // 当月变化时显示的时间
        monthWV.addChangingListener(new OnWheelChangedListener() {

            @Override
            public void onChanged(WheelView wheel, int oldValue, int newValue) {
                // TODO Auto-generated method stub
                // 获取年和月
                year = Integer.parseInt(yearArrayString[yearWV.getCurrentItem()]);
                month = Integer.parseInt(monthArrayString[monthWV
                        .getCurrentItem()]);
                // 根据年和月生成天数数组
                dayArrayString = getDayArray(getDay(year, month));
                // 给天数的滚轮设置数据
                dayWV.setAdapter(new ArrayWheelAdapter<String>(dayArrayString));
                // 防止数组越界
                if (dayWV.getCurrentItem() >= dayArrayString.length) {
                    dayWV.setCurrentItem(dayArrayString.length - 1);
                }
                // 显示的时间
                showDate();
            }
        });
    }

    /**
     * 给滚轮提供数据
     */
    private static void setData2() {
        // 给滚轮提供数据
        yearWV.setAdapter(new ArrayWheelAdapter<String>(yearArrayString));
        monthWV.setAdapter(new ArrayWheelAdapter<String>(monthArrayString));
        //hourWV.setAdapter(new ArrayWheelAdapter<String>(hourArrayString));
        //minuteWV.setAdapter(new ArrayWheelAdapter<String>(minuteArrayString));

        yearWV.addChangingListener(new OnWheelChangedListener() {
            @Override
            public void onChanged(WheelView wheel, int oldValue, int newValue) {
                // TODO Auto-generated method stub
                // 获取年和月
                year = Integer.parseInt(yearArrayString[yearWV.getCurrentItem()]);
                month = Integer.parseInt(monthArrayString[monthWV
                        .getCurrentItem()]);
                // 根据年和月生成天数数组
                dayArrayString = getDayArray(getDay(year, month));
                // 给天数的滚轮设置数据
                dayWV.setAdapter(new ArrayWheelAdapter<String>(dayArrayString));
                // 防止数组越界
                if (dayWV.getCurrentItem() >= dayArrayString.length) {
                    dayWV.setCurrentItem(dayArrayString.length - 1);
                }
                // 显示的时间
                showDate2();
            }
        });

        // 当月变化时显示的时间
        monthWV.addChangingListener(new OnWheelChangedListener() {

            @Override
            public void onChanged(WheelView wheel, int oldValue, int newValue) {
                // TODO Auto-generated method stub
                // 获取年和月
                year = Integer.parseInt(yearArrayString[yearWV.getCurrentItem()]);
                month = Integer.parseInt(monthArrayString[monthWV
                        .getCurrentItem()]);
                // 根据年和月生成天数数组
                dayArrayString = getDayArray(getDay(year, month));
                // 给天数的滚轮设置数据
                dayWV.setAdapter(new ArrayWheelAdapter<String>(dayArrayString));
                // 防止数组越界
                if (dayWV.getCurrentItem() >= dayArrayString.length) {
                    dayWV.setCurrentItem(dayArrayString.length - 1);
                }
                // 显示的时间
                showDate2();
            }
        });
    }

    // 设定初始时间
    static void setOriTime2(String datenow) {
        if (!datenow.equals("") && !datenow.equals("请选择")) {
            yearWV.setCurrentItem(getNumData(datenow.split("-")[0], yearArrayString));
            monthWV.setCurrentItem(getNumData(Integer.valueOf(datenow.split("-")[1]) + "", monthArrayString) + 0);
            dayArrayString = getDayArray(getDay(year, month));
            dayWV.setAdapter(new ArrayWheelAdapter<String>(dayArrayString));
            dayWV.setCurrentItem(getNumData(datenow.split("-")[2] + "", dayArrayString));
        } else {
            yearWV.setCurrentItem(getNumData(c.get(Calendar.YEAR) + "",
                    yearArrayString));
            monthWV.setCurrentItem(getNumData(c.get(Calendar.MONTH) + 1 + "",
                    monthArrayString) + 0);
//        hourWV.setCurrentItem(getNumData(c.get(Calendar.HOUR_OF_DAY) + "",
//                hourArrayString));
//        minuteWV.setCurrentItem(getNumData(c.get(Calendar.MINUTE) + "",
//                minuteArrayString));

            dayArrayString = getDayArray(getDay(year, month));
            dayWV.setAdapter(new ArrayWheelAdapter<String>(dayArrayString));
            dayWV.setCurrentItem(getNumData(c.get(Calendar.DAY_OF_MONTH) + "",
                    dayArrayString));
        }
        // 初始化显示的时间
        showDate2();
    }

    // 设定过去两年的初始时间
    static void setOriTime3() {
        yearWV.setCurrentItem(getNumData(c.get(Calendar.YEAR) - 2 + "",
                yearArrayString));
        monthWV.setCurrentItem(getNumData(c.get(Calendar.MONTH) + 1 + "",
                monthArrayString) + 0);
//        hourWV.setCurrentItem(getNumData(c.get(Calendar.HOUR_OF_DAY) + "",
//                hourArrayString));
//        minuteWV.setCurrentItem(getNumData(c.get(Calendar.MINUTE) + "",
//                minuteArrayString));

        dayArrayString = getDayArray(getDay(year, month));
        dayWV.setAdapter(new ArrayWheelAdapter<String>(dayArrayString));
        dayWV.setCurrentItem(getNumData(c.get(Calendar.DAY_OF_MONTH) + "",
                dayArrayString));

        // 初始化显示的时间
        showDate2();
    }

    // 显示时间
    static String showDate2() {
        return createDate2(yearArrayString[yearWV.getCurrentItem()],
                monthArrayString[monthWV.getCurrentItem()],
                dayArrayString[dayWV.getCurrentItem()]);
    }

    // 设定初始时间
    static void setOriTime() {
        yearWV.setCurrentItem(getNumData(c.get(Calendar.YEAR) + "",
                yearArrayString));
        monthWV.setCurrentItem(getNumData(c.get(Calendar.MONTH) + 1 + "",
                monthArrayString) + 0);
        hourWV.setCurrentItem(getNumData(c.get(Calendar.HOUR_OF_DAY) + "",
                hourArrayString));
        minuteWV.setCurrentItem(getNumData(c.get(Calendar.MINUTE) + "",
                minuteArrayString));

        dayArrayString = getDayArray(getDay(year, month));
        dayWV.setAdapter(new ArrayWheelAdapter<String>(dayArrayString));
        dayWV.setCurrentItem(getNumData(c.get(Calendar.DAY_OF_MONTH) + "",
                dayArrayString));

        // 初始化显示的时间
        showDate();
    }

    // 显示时间
    static String showDate() {
        return createDate(yearArrayString[yearWV.getCurrentItem()],
                monthArrayString[monthWV.getCurrentItem()],
                dayArrayString[dayWV.getCurrentItem()],
                hourArrayString[hourWV.getCurrentItem()],
                minuteArrayString[minuteWV.getCurrentItem()]);
    }


    // 生成时间
    static String createDate(String year, String month, String day,
                             String hour, String minute) {
        String mon = DateUtils.fillZero(Integer.parseInt(month));
        String d = DateUtils.fillZero(Integer.parseInt(day));
        String h = DateUtils.fillZero(Integer.parseInt(hour));
        String m = DateUtils.fillZero(Integer.parseInt(minute));
        return year + "-" + mon + "-" + d + " " + h + ":" + m;

        // time_TV.setText("选择时间为：" + dateStr);String dateStr =
    }

    // 生成时间
    static String createDate2(String year, String month, String day) {
        String mon = DateUtils.fillZero(Integer.parseInt(month));
        String d = DateUtils.fillZero(Integer.parseInt(day));
        return year + "-" + mon + "-" + d;

        // time_TV.setText("选择时间为：" + dateStr);String dateStr =
    }

    // 在数组Array[]中找出字符串s的位置
    static int getNumData(String s, String[] Array) {
        int num = 0;
        for (int i = 0; i < Array.length; i++) {
            if (s.equals(Array[i])) {
                num = i;
                break;
            }
        }
        return num;
    }

    // 根据当前年份和月份判断这个月的天数
    public static int getDay(int year, int month) {
        int day;
        if (year % 4 == 0 && year % 100 != 0) { // 闰年
            if (month == 1 || month == 3 || month == 5 || month == 7
                    || month == 8 || month == 10 || month == 12) {
                day = 31;
            } else if (month == 2) {
                day = 29;
            } else {
                day = 30;
            }
        } else { // 平年
            if (month == 1 || month == 3 || month == 5 || month == 7
                    || month == 8 || month == 10 || month == 12) {
                day = 31;
            } else if (month == 2) {
                day = 28;
            } else {
                day = 30;
            }
        }
        return day;
    }

    // 根据数字生成一个字符串数组
    public static String[] getDayArray(int day) {
        String[] dayArr = new String[day];
        for (int i = 0; i < day; i++) {
            dayArr[i] = i + 1 + "";
        }
        return dayArr;
    }

    // 根据数字生成一个字符串数组2(天)
    public static String[] getDayArray2(int startday, int lastday) {
        int total = lastday - startday + 1;
        String[] dayArr = new String[total];
        for (int i = startday; i <= lastday; i++) {
            dayArr[i] = i + "";
        }
        return dayArr;
    }

    // 根据数字生成一个字符串数组
    public static String[] getHMArray(int day) {
        String[] dayArr = new String[day];
        for (int i = 0; i < day; i++) {
            dayArr[i] = i + "";
        }
        return dayArr;
    }

    // 根据初始值start和step得到一个字符数组，自start起至start+step-1
    public static String[] getYEARArray(int start, int step) {
        String[] dayArr = new String[step];
        for (int i = 0; i < step; i++) {
            dayArr[i] = start + i + "";
        }
        return dayArr;
    }

    /**
     * 选择时间日期对话框
     */
    private AlertDialog builder;

    public void showPicker(Activity activity) {

        View view1 = View.inflate(activity, R.layout.date_time_picker, null);
        final DatePicker datePicker = (DatePicker) view1
                .findViewById(R.id.new_act_date_picker);
        final TimePicker timePicker = (TimePicker) view1
                .findViewById(R.id.new_act_time_picker);

        // Init DatePicker
        int year, month, day, hour, minute;
        // Use the current date as the default date in the picker
        Calendar c = Calendar.getInstance();
        year = c.get(Calendar.YEAR);
        month = c.get(Calendar.MONTH);
        day = c.get(Calendar.DAY_OF_MONTH);
        datePicker.init(year, month, day, null);

        // Init TimePicker
        final Calendar c1 = Calendar.getInstance();
        hour = c1.get(Calendar.HOUR_OF_DAY);
        minute = c1.get(Calendar.MINUTE);
        timePicker.setIs24HourView(true);
        timePicker.setCurrentHour(hour);
        timePicker.setCurrentMinute(minute);

        builder = new AlertDialog.Builder(activity, R.style.Theme_Transparent)
                .create();
        builder.setView(view1);
        builder.show();
        ((Button) view1.findViewById(R.id.btn_cancel))
                .setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        builder.dismiss();
                    }
                });

        ((Button) view1.findViewById(R.id.btn_ok))
                .setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        String date = datePicker.getYear() + ("-")
                                + (datePicker.getMonth() + 1) + ("-")
                                + datePicker.getDayOfMonth();
                        String time = timePicker.getCurrentHour() + ":"
                                + timePicker.getCurrentMinute();

                        // trans_date.setText(date+" "+time);
                        builder.dismiss();
                    }
                });
    }

    /**
     * 返回提示
     *
     * @param activity
     * @param listener
     * @return
     * @author dignyg
     */
    public static Dialog createEjectNoticeDialog(final Activity activity, OnClickListener listener) {

        View view = LayoutInflater.from(activity).inflate(
                R.layout.view_ejectnotice, null);
        final Dialog dialog = new Dialog(activity, R.style.dialog);
        dialog.setContentView(view);
        Button okButton = (Button) view.findViewById(R.id.ok);
        Button cancelButton = (Button) view.findViewById(R.id.cancel);
        cancelButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                dialog.dismiss();
            }
        });
        if (listener != null) {
            okButton.setOnClickListener(listener);
        }
        return dialog;
    }

    /**
     * 预订单提交提示
     *
     * @param activity
     * @param listener
     * @return
     * @author dignyg
     */
    public static Dialog createSaveorderDialog(final Activity activity, OnClickListener listener) {

        View view = LayoutInflater.from(activity).inflate(
                R.layout.view_saveorder, null);
        final Dialog dialog = new Dialog(activity, R.style.dialog);
        dialog.setContentView(view);
        Button okButton = (Button) view.findViewById(R.id.save);
        Button cancelButton = (Button) view.findViewById(R.id.cancel);
        cancelButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                dialog.dismiss();
            }
        });
        if (listener != null) {
            okButton.setOnClickListener(listener);
        }
        return dialog;
    }

    /*
    跳出是否派工成功的dialog
    @author dingyg
     */
    public static Dialog showTaskingDialog(final Activity activity, int imageId, String HintText) {

        View view = LayoutInflater.from(activity).inflate(
                R.layout.view_showpg_issuccessful, null);
        final Dialog dialog = new Dialog(activity, R.style.dialog1);
        ImageView imgView = (ImageView) view.findViewById(R.id.ivfIsSuccessful);
        imgView.setImageResource(imageId);
        TextView tvfText = (TextView) view.findViewById(R.id.tvfIsSuccessful);
        tvfText.setText(HintText);
        dialog.setContentView(view);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                dialog.dismiss();
            }
        }, 2000);
        return dialog;
    }

    /**
     * 版本更新提示
     *
     * @param activity
     * @param listener
     * @return
     * @author dignyg
     */
    public static Dialog createUpdateDialog(final Activity activity, OnClickListener listener) {

        View view = LayoutInflater.from(activity).inflate(
                R.layout.view_update, null);
        final Dialog dialog = new Dialog(activity, R.style.dialog);
        dialog.setContentView(view);
        Button okButton = (Button) view.findViewById(R.id.save);
        Button cancelButton = (Button) view.findViewById(R.id.cancel);
        cancelButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                dialog.dismiss();
            }
        });
        if (listener != null) {
            okButton.setOnClickListener(listener);
        }
        return dialog;
    }
}
